$(function(){
			$.post("/getRequestByCoach",{"uid":$("#uid").val()},function(data){
				if(data.cid!=0) {
                    acceptByCoach(data.cname, data);
                  //  alert(1);
                }else{
				  //  alert(1);
                    showDefaultCoachInfo();
				  /*  $.post("getCoachInformation",function (info) {
                        showDefaultCoachInfo();
                    })*/
                }
			});
});

			
function acceptByCoach(cname,data){
	if(confirm("您是否接受"+cname+"的教练请求?")){
		showCoachInfo(data);
		$.post("connectMemberSuccess",{"uid":$("#uid").val()},function () {
            $("#info").css("display","block");
            $("#msg").html("<p style='font-size:40px;padding-top:30px;color:green;text-align: center'>成功</p>");
            window.setTimeout(function(){
                $("#info").css("display","none");
            },1500);
        })
	}
}

function showDefaultCoachInfo() {
    var coachInfo = ""+ "<figure>"+
        "<img src='images/trainer10.png'>"+
        "</figure><span style='border-bottom:1px #ffffff solid;'>"+ "教练名称"+
        "</span><span style='border-bottom:1px #ffffff solid;'>"+"手机号码"+ "</span>"+
        "<span style='color: #0f0f0f;'>"+"尚未关联教练信息"+"</span>";
    console.log(coachInfo);
    $("#coachInfo").html(coachInfo);
}

function showCoachInfo(data){
	var coachInfo = ""+
				   "<figure>"+
				   "<img src='images/"+data.sample+"'>"+
				   "</figure><span style='border-bottom:1px #ffffff solid;'>"+
					data.cname+
					"</span><span style='border-bottom:1px #ffffff solid;'>"+
					data.mobile+
					"</span>"+
					"<a href='' onclick='stopConnect("+$("#uid").val()+")'>"+"<span style='color: #0f0f0f;'>"+"取消关联"+"</span>"+"</a>"
  ;
	$("#coachInfo").html(coachInfo);
}

function stopConnect(uid){
    if(confirm("您确定要取消与该教练的联系吗？")){
        $.post("/connectMemberStop",{"uid":uid},function() {
            $("#info").css("display","block");
            $("#msg").html("<p style='font-size:40px;padding-top:30px;color:green;'>成功</p>");
            window.setTimeout(function(){
                $("#info").css("display","none");
            },1500);
        });
        showDefaultCoachInfo();
    }
}